// pages/apis/apis.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    imageList: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  login() {
    wx.login().then(res => {
      console.log(res);
    })
  },
  getUserInfo() {
    wx.getUserInfo({
      success: (res) => {
        console.log(res);
        var userInfo = res.userInfo
        this.setData({ userInfo })
        var nickName = userInfo.nickName
        var avatarUrl = userInfo.avatarUrl
        var gender = userInfo.gender //性别 0：未知、1：男、2：女
        var province = userInfo.province
        var city = userInfo.city
        var country = userInfo.country
      }
    })
  },
  getLocation() {
    wx.getLocation({
      type: 'wgs84',
      success: (res) => {
        console.log(res);
        var latitude = res.latitude // 纬度
        var longitude = res.longitude // 经度
      }
    })
  },
    // 调用微信扫一扫api
    getScanCode() {
      wx.scanCode({
        success: (res) => {
          console.log(res)
        }
      })
    },
  openLocation: (e) => {
    wx.getLocation({
      success: (res) => {
        console.log(res)
        wx.openLocation({
          longitude: res.longitude,
          latitude: res.latitude,
        })
      }
    })
  },
  getImage() {
    wx.chooseImage({
      success: (res) => {
        this.setData({
          imageList: res.tempFilePaths
        })
      }
    })
  },
  previewImage: function (e) {
    var current = e.target.dataset.src
    wx.previewImage({
      current: current,
      urls: this.data.imageList
    })
  }
})